package com.heima.article.web;

import com.heima.article.service.ArticleService;
import com.heima.model.article.dto.ArticleHomeDto;
import com.heima.model.article.pojo.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @PostMapping("/load")
    public ResponseResult<List<ApArticle>> load(@RequestBody ArticleHomeDto dto){
        List<ApArticle> list = articleService.load(dto);
        return ResponseResult.okResult(list);
    }

    /**
     * 下滑
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult<List<ApArticle>> loadmore(@RequestBody ArticleHomeDto dto){
        List<ApArticle> list = articleService.loadmore(dto);
        return ResponseResult.okResult(list);
    }

    /**
     * 上滑
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult<List<ApArticle>> loadnew(@RequestBody ArticleHomeDto dto){
        List<ApArticle> list = articleService.loadnew(dto);
        return ResponseResult.okResult(list);
    }

    /**
     * 根据文章id查询文章对象
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ApArticle findById(@PathVariable("id") Long id){
        return articleService.findById(id);
    }
}
